<%@page import="com.surelution.projects.crm.Market"%>
<%@ page contentType="text/html;charset=UTF-8" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<meta name="layout" content="main"/>
<g:set var="entityName" value="${message(code: 'market.label', default: 'Market')}" />
<g:javascript library="jquery"/>
<resource:dateChooser />
<link rel="stylesheet" href="${resource(dir:'css',file:'defaultTheme.css')}" />
<script type="text/javascript" src="${resource(dir:'js/jquery',file:'jquery.fixedheadertable.min.js')}"></script>
<script type="text/javascript" src="${resource(dir:'js/jquery',file:'jquery.printElement.min.js')}"></script>
<script type="text/javascript" src="${resource(dir:'js/datechooser',file:'datechooser.js')}"></script>
<title>${message(code: 'market.report.label', default: 'report')}</title>
	<script type="text/javascript">
		$(document).ready(function() {
		   $("#simplePrint").click(function() {
		       printElem({leaveOpen: true, printMode: 'popup', overrideElementCSS: ["${resource(dir:'plugins/richui-0.8/css',file:'calendarmonthview.css')}","${resource(dir:'css',file:'main.css')}"]});
		   });
		   $('#myTable01').fixedHeaderTable({ footer: false, cloneHeadToFoot: false, autoShow: true });
		});
		function printElem(options){
		    $('#monthReport').printElement(options);
		};
		
	</script>
</head>

<body>
  <div class="body">
          <div class="nav">
            <span class="menuButton"><a class="home" href="${createLink(uri: '/')}"><g:message code="default.home.label"/></a></span>
          </div>
          <div>
            <p style="font-size:16px;color:#000;margin:10px 0;">${message(code: 'market.report.label', default: 'report')}</p>
        	<g:form action="report">
        		选择月份：  	<g:datePicker name="startDay" precision="month" value="${startDay}" />至<g:datePicker name="endDay" precision="month" value="${endDay}" />
        		购油量范围：<g:textField name="saleNumberA" value="${saleNumberA}" />至<g:textField name="saleNumberB" value="${saleNumberB}" /><br><br>
       			<sec:ifAnyGranted roles="ROLE_ADMIN">
	        		 选择片区：
	        		<g:each in="${com.surelution.projects.crm.StationArea.list()}" var="area">
		    			<g:checkBox id="stationArea.id_${area.id }" name="stationArea" value="${area.id }" checked="${stationArea!=[]?stationArea.contains(area.id):true}"/><label for="stationArea.id_${area.id }">${area.areaName}</label>&nbsp;
	    			</g:each>	
    			</sec:ifAnyGranted>
				<span class="menuButton" style="margin-right:5px;"><g:actionSubmit value="${message(code: 'default.button.search.label', default: '查询')}" action="report"/></span>
			    <input type="button" value="打印报表" id="simplePrint" />
			    <span class="menuButton"><g:actionSubmit value="${message(code: 'default.button.export.label', default: 'Export')}" action="exportMarket"/></span>
    		</g:form>
			<g:if test="${flash.message}">
            	<div class="message">${flash.message}</div>
            </g:if>
        </div>
        
        <div id="monthReport" style="height:620px;">
			<label style="font-size:16px;color:#0f3072;">查询时间段：  ${startDay?.format("yyyy年MM月")}到${endDay?.format("yyyy年MM月")} </label>
        		<table id="myTable01" >
        		<thead>
	        		<tr>
	        			<td style="text-align: center;vertical-align: middle;background:#75746a;color:#fff;width:30px;">编号</td>
	        			<td style="text-align: center;vertical-align: middle;background:#75746a;color:#fff;width:50px;">片区</td>
	          			<td style="text-align: center;vertical-align: middle;background:#75746a;color:#fff;width:250px;">客户名称</td>
	          			<td style="text-align: center;vertical-align: middle;background:#75746a;color:#fff;width:150px;">客户主卡号</td>
	          			<td style="text-align: center;vertical-align: middle;background:#75746a;color:#fff;width:300px;">地址</td>
	          			<td style="text-align: center;vertical-align: middle;background:#75746a;color:#fff;width:80px;">联系人</td>
	          			<td style="text-align: center;vertical-align: middle;background:#75746a;color:#fff;width:100px;">联系人电话</td>
	          			<td style="text-align: center;vertical-align: middle;background:#75746a;color:#fff;">总购油量(吨)</td>
	    			</tr>
				</thead>
				<tbody>
    				<g:each in="${result}" var="r" status="i">
					<tr class="${(i % 2) == 0 ? 'odd' : 'even'}">
    					<td style="text-align:center;">${i+1}</td>
    					<td style="text-align:center;">${r[0].area.areaName}</td>
    					<td style="text-align:center;"><g:link action="show" id="${r[0].id}">${r[0].name}</g:link></td>
    					<td style="text-align:center;">${r[0].marketCardNo}</td>
    					<td style="text-align:center;">${r[0].address}</td>
    					<td style="text-align:center;">${r[0].manager}</td>
    					<td style="text-align:center;">${r[0].managerTel}</td>
    					<td style="text-align:center;"><g:formatNumber number="${r[1]}" type="number" maxFractionDigits="1" /></td>
    				</tr>
    				</g:each>
    			</tbody>
          	</table>
        </div>

  </div>
</body>
</html>